package com.sx.zongzhi.adapter;


import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.BusinessBean;
import com.sx.zongzhi.widget.NoScrollGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by XZY on 2017/12/4.
 * 业务信息adapter
 */

public class BusinessAdapter extends BaseQuickAdapter<BusinessBean,BaseViewHolder> {

    private Context context;
    private List<String> selectList;
    /**是否可以选择*/
    private boolean isSelect;

    public BusinessAdapter(Context context, @LayoutRes int layoutResId,
                           @Nullable List<BusinessBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    public void selectData(List<String> lists){
        selectList=lists;
    }

    public void setSelected(boolean isSelect){
        this.isSelect=isSelect;
    }

    public List<String> getSelectList() {
        return selectList;
    }

    @Override
    protected void convert(BaseViewHolder helper, final BusinessBean item) {
        helper.setText(R.id.tv_Title,item.getTypeCname());
        if (item.getSubTypes()!=null&&item.getSubTypes().size()>0){
            NoScrollGridView gridView=helper.getView(R.id.gridView);
            BusinessSelectAdapter adapter=new BusinessSelectAdapter(context,
                    R.layout.item_business_list2,item.getSubTypes());
            if (selectList!=null){
                adapter.selectData(selectList);
            }
            adapter.setSelected(isSelect);
            gridView.setAdapter(adapter);
            adapter.getBusiness(new BusinessSelectAdapter.BusinessCallback() {
                @Override
                public void addBusiness(String str) {
                    if (selectList==null){
                        selectList=new ArrayList<String>();
                    }
                    if ("positiveInfo".equals(str)||"rectificativePerson".equals(str)){
                        selectList.remove("positiveInfo");
                        selectList.remove("rectificativePerson");
                        selectList.add(str);
                        notifyDataSetChanged();
                    }else {
                        selectList.add(str);
                    }
                }
                @Override
                public void deleteBusiness(String str) {
                   selectList.remove(str);
                }
            });
        }
    }
}
